home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / E / Fireworks / FiReWoRkS.e next >
Encoding:
Text File  |  1997-05-03  |  10.2 KB  |  340 lines

  1. /*
  2.  * GMS FiReWoRkS (c) 1996 Richard Clark - PhiRatE
  3.  *
  4.  * Fireworks using GMS in E, Requires E 3.0+
  5.  *
  6.  * Code and execs freely distributable. If you use complete functions from
  7.  * this code, please put my name somewhere in your docs. And send me email
  8.  * about your software. This applies to commercial software as well :).
  9.  * 
  10.  * Note: The timings etc were set up for an A1200 +fast, they could look
  11.  *       quite sad on anything slower, but on a fast machine, go ahead and
  12.  *       decrease the delay values in the process procedures!
  13.  *
  14.  * Recommended timing for 040+ ... Change all of 'em to 3 or lower! >:)
  15.  */
  16.  
  17. OPT PREPROCESS  -> Allow our function defines
  18.  
  19. MODULE 'games','games/games','games/sound'
  20. MODULE '*fireworksmod','*wordims'
  21.  
  22. ENUM ERR_NONE,ERR_REFUSE,ERR_FATAL
  23.  
  24. DEF screen:PTR TO gamescreen, explosive:PTR TO sound,sparks:PTR TO sound
  25.  
  26. PROC init()
  27.   IF (gmsbase:=OpenLibrary('GMS:GPI/Master.GPI',0))=NIL
  28.     Throw(ERR_FATAL,'Cannot load GMS!!')  -> Throw pointer to message
  29.   ENDIF
  30.  
  31.   SetUserPrefs(NIL)
  32.  
  33.   screen := AddScreen([TAGS_GAMESCREEN,0,
  34.    GSA_PALETTE,{pal},
  35.    GSA_SCRWIDTH,320,
  36.    GSA_SCRHEIGHT,256,
  37.    GSA_AMTCOLOURS,32,
  38.    GSA_RASTERLIST,[WAITLINE(180),
  39.                    MIRROR,
  40.                    NEWPALETTE(0,32,{waterpal}),
  41.                    RASTEND],
  42.    TAGEND])
  43.  
  44.   AllocAudio()
  45.   AllocBlitter()  -> We use GMS blitter functions so we must alloc
  46. ENDPROC
  47.  
  48. /* Deallocate stuff */
  49.  
  50. PROC deinit()
  51.   FreeBlitter()
  52.   FreeAudio()
  53.   IF screen THEN DeleteScreen(screen); screen := 0;
  54.   IF gmsbase THEN CloseGMS(); gmsbase := 0;
  55. ENDPROC
  56.  
  57. PROC main() HANDLE
  58. /*
  59.  * Lets make big bangs and little bangs and colourful bangs and well, you
  60.  * get the picture.
  61.  */
  62.  
  63.   DEF fwork:PTR TO firework,fwlist=NIL:PTR TO firework,count=NIL,nxt,pc=NIL
  64.   DEF temp=NIL
  65.  
  66.   explosive := [
  67.    SMV1,0,           -> Structure version.
  68.    CHANNEL_ALL,      -> Channel to play through.
  69.    1,                -> Priority.
  70.    0,                -> Header
  71.    0,                -> Address.
  72.    0,                -> Length.
  73.    OCT_C3,           -> Period.
  74.    100,              -> Volume.
  75.    0,                -> Attributes.
  76.    {file_explosive}  -> Sample file.
  77.   ]:sound;
  78.  
  79.   sparks := [
  80.    SMV1,0,           -> Structure version.
  81.    CHANNEL1,         -> Channel to play through.
  82.    2,                -> Priority.
  83.    0,                -> Header
  84.    0,                -> Address.
  85.    0,                -> Length.
  86.    OCT_C3,           -> Period.
  87.    50,               -> Volume.
  88.    SREPEAT,          -> Attributes.
  89.    {file_sparks}     -> Sample file.
  90.   ]:sound;
  91.  
  92.   init()
  93.   InitSound(explosive)
  94.   InitSound(sparks)
  95.  
  96.   ShowScreen(screen)  -> Display the GMS screen
  97.  
  98.   count:=100
  99.  
  100.   REPEAT
  101.  
  102.     INC count
  103.     INC pc
  104.  
  105.     IF pc>4000    -> Loop at 100 seconds (1 minute 20secs)
  106.       pc:=0
  107.       count:=100
  108.     ENDIF
  109.  
  110.     -> Complete routine list and timing
  111.  
  112.     IF pc>1090
  113.       fwlist,count := fast_single(fwlist,count)
  114.     ELSEIF pc>1060
  115.       -> do nothing
  116.     ELSEIF pc>1000
  117.       fwlist,count,temp := char_word(fwlist,count,'BYE',temp)
  118.     ELSEIF pc>600
  119.       fwlist,count := fast_double(fwlist,count)
  120.     ELSEIF pc>599
  121.       count:=80            -> Make sure fast_dobe starts right up
  122.     ELSEIF pc>170
  123.       fwlist,count := thick_fountain(fwlist,count,pc)
  124.     ELSEIF pc>100
  125.       fwlist,count,temp := char_word(fwlist,count,'GMS',temp)
  126.     ELSEIF pc>10
  127.       -> do nothing
  128.     ELSEIF pc>0
  129.       fwlist,count := slow_huge(fwlist,count)
  130.     ENDIF
  131.  
  132.     fwork:=fwlist
  133.  
  134.     WHILE fwork
  135.       nxt:=fwork.next -> Get the next one for safety
  136.  
  137.       fwork.clear(screen,BUFFER1)  -> Clear the firework from the screen
  138.       fwlist:=fwork.update(fwlist)  -> Update the firework
  139.  
  140.       IF (fwork.flags AND FW_KILLME)  -> If firework is to be killed..
  141.         END fwork                     -> Kill it :)
  142.       ELSE
  143.         fwork.draw(screen,BUFFER1) -> Draw the firework
  144.       ENDIF
  145.  
  146.       fwork:=nxt  -> Loop with next one!
  147.     ENDWHILE
  148.  
  149.     WaitVBL()
  150.  
  151.   UNTIL (ReadMouse(JPORT1) AND MB_LMB)
  152.  
  153. EXCEPT DO -> If there's an error or we're at the end, dealloc.
  154.  
  155.   FreeSound(sparks)
  156.   FreeSound(explosive)
  157.   deinit()
  158.  
  159.   -> Quick, easy, and friendly way of displaying an error
  160.  
  161.   IF exception
  162.     EasyRequestArgs(0,[20,0,'Fireworks error:',exceptioninfo,'DAMN'],0,NIL)
  163.   ELSE
  164.     EasyRequestArgs(0,[100,50,'FiReWoRkS!!',
  165.         'This demo was written by PhiRatE using\nAmigaE v3.1 and GMS!!\n\nE-mail: phirate@sans.vuw.ac.nz',
  166.         'Woohoo!'],0,NIL)
  167.   ENDIF
  168.  
  169. ENDPROC
  170.  
  171.  
  172.          /*-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-*-*/
  173.          /* Firework process procedures for different displays  */
  174.          /*-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-*-*/
  175.  
  176.  
  177. /****************************************************************************
  178. ** Fast, single-explosion fireworks.
  179. */
  180.  
  181. PROC fast_single(fwlist:PTR TO firework,count)
  182.  
  183.   DEF f:PTR TO firework,p,flags
  184.  
  185.   IF count>=10    -> CHANGE THIS NUMBER IF YOU GOT A FAST MACHINE!! :)
  186.     count:=0
  187.     p:=Shr(FastRandom(12),1)
  188.     IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
  189.     flags:=flags OR FW_BIGSPARK -> Big spark
  190.  
  191.     NEW f.new(160,180,            -> X and Y start
  192.               FastRandom(5)-2,FastRandom(4)+3,  -> X and Y velocities
  193.               4,                  -> Gravity delay
  194.               (p*4)+8,            -> Color value
  195.               0,                  -> Background color
  196.               25,                 -> Firework lifetime
  197.               1,                  -> Number of explosions
  198.               flags)              -> Flags
  199.  
  200.     IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
  201.   ENDIF
  202. ENDPROC fwlist,count
  203.  
  204. /****************************************************************************
  205. ** Fast, with the occasional double-explosion.
  206. */
  207.  
  208. PROC fast_double(fwlist:PTR TO firework,count)
  209.  
  210.   DEF f:PTR TO firework,p,flags
  211.  
  212.   IF count>=60
  213.     count:=0
  214.     p:=Shr(FastRandom(12),1)
  215.     IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
  216.     flags:=flags OR FW_BIGSPARK OR FW_EXSOUND -> Explosion-sparks get same flags
  217.  
  218.     NEW f.new(160,180,            -> X and Y start
  219.               FastRandom(5)-2,FastRandom(3)+4,  -> X and Y velocities
  220.               4,                  -> Gravity delay
  221.               (p*4)+8,            -> Color value
  222.               0,                  -> Background color
  223.               25,                 -> Firework lifetime
  224.               2,                  -> Number of explosions
  225.               flags)              -> Flags
  226.  
  227.     IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
  228.   ENDIF
  229. ENDPROC fwlist,count
  230.  
  231. /****************************************************************************
  232. ** Slow but massive bangs :)
  233. */
  234.  
  235. PROC slow_huge(fwlist:PTR TO firework,count)
  236.  
  237.   DEF f:PTR TO firework,p,flags
  238.  
  239.   IF count>=100
  240.     count:=0
  241.     p:=Shr(FastRandom(12),1)
  242.     IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
  243.     flags:=flags OR FW_BIGSPARK OR FW_MASSIVE OR FW_EXSOUND  -> Big spark
  244.     NEW f.new(160,180,            -> X and Y start
  245.               FastRandom(5)-2,FastRandom(4)+3,  -> X and Y velocities
  246.               4,                  -> Gravity delay
  247.               (p*4)+8,            -> Color value
  248.               0,                  -> Background color
  249.               25,                 -> Firework lifetime
  250.               1,                  -> Number of explosions
  251.               flags)              -> Flags
  252.  
  253.     IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
  254.   ENDIF
  255. ENDPROC fwlist,count
  256.  
  257. /****************************************************************************
  258. ** Explodes into the word, letter by letter.
  259. */
  260.  
  261. PROC char_word(fwlist:PTR TO firework,count,word:PTR TO CHAR,c)
  262.  
  263.   DEF f:PTR TO firework,p,flags,xv
  264.  
  265.   IF count>=25
  266.     count:=0
  267.     IF c>=StrLen(word) THEN c:=0
  268.     xv:=(2*(c-Shr(StrLen(word),1)))/Shr(StrLen(word),1)
  269.     p:=Shr(FastRandom(12),1)
  270.     IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
  271.     flags:=flags OR FW_BIGSPARK OR FW_IMAGE OR FW_KEEPFLAGS   -> Big spark
  272.  
  273.     NEW f.new(160,180,            -> X and Y start
  274.               xv,FastRandom(3)+4, -> X and Y velocities
  275.               4,                  -> Gravity delay
  276.               (p*4)+8,            -> Color value
  277.               0,                  -> Background color
  278.               25,                 -> Firework lifetime
  279.               1,                  -> Number of explosions
  280.               flags,              -> Flags
  281.               2,2,getchar(word,c))-> Character display system
  282.  
  283.     IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
  284.     INC c
  285.   ENDIF
  286. ENDPROC fwlist,count,c
  287.  
  288. /****************************************************************************
  289. ** Big funky fountain.
  290. */
  291.  
  292. PROC thick_fountain(fwlist:PTR TO firework,count,pc)
  293.  
  294.   DEF f:PTR TO firework,p,flags
  295.  
  296.   IF (pc<200) THEN PlaySound(sparks)
  297.  
  298.   IF count>=2
  299.     count:=0
  300.     p:=Shr(FastRandom(12),1)
  301.     IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
  302.     flags:=flags OR FW_BIGSPARK OR FW_SMALL OR FW_KEEPFLAGS  -> Big spark
  303.  
  304.     NEW f.new(160,180,            -> X and Y start
  305.               FastRandom(3)-1,FastRandom(4)+2,  -> X and Y velocities
  306.               4,                  -> Gravity delay
  307.               (p*4)+8,            -> Color value
  308.               0,                  -> Background color
  309.               10,                 -> Firework lifetime
  310.               1,                  -> Number of explosions
  311.               flags)              -> Flags
  312.  
  313.     IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
  314.   ENDIF
  315. ENDPROC fwlist,count
  316.  
  317. -> Standard palette, stored here simply because I needed to make sure
  318. -> that the water palette was similar. Converted to 12bit to make it ECS-OK
  319.  
  320. pal:
  321. LONG $000000,$000000,$000010,$000010,$000030,$000050,$000060,$000070
  322. LONG $F0F000,$A06000,$803000,$400000,$F0F0F0,$A0A0A0,$707070,$404040
  323. LONG $F00000,$A00000,$700000,$400000,$00F000,$00A000,$007000,$004000
  324. LONG $A0A0F0,$8080A0,$606070,$202040,$F0F000,$A0A000,$707000,$404000
  325.  
  326. waterpal:
  327. LONG $000010,$000020,$000020,$000040,$000050,$000060,$000070,$000080
  328. LONG $A0A060,$804040,$602020,$300010,$8080A0,$707080,$303040,$101020
  329. LONG $A00020,$800020,$500020,$300020,$00A020,$008020,$005020,$003020
  330. LONG $7070A0,$404080,$202050,$000020,$A0A020,$808020,$505020,$303020
  331.  
  332. -> Water palette, same palette with a bit of blue and some dimming
  333.  
  334. file_explosive:
  335.  CHAR 'GMS:demos/data/SND.Explosive',0
  336. file_sparks:
  337.  CHAR 'GMS:demos/data/SND.Sparks',0
  338.  
  339.  
  340.